﻿using System;
using HslCommunication.Core;
using HslCommunication.Reflection;
using HslCommunication.Serial;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 基于Qna 兼容3C帧的格式一的通讯，具体的地址需要参照三菱的基本地址<br />
	/// Based on Qna-compatible 3C frame format one communication, the specific address needs to refer to the basic address of Mitsubishi.
	/// </summary>
	/// <remarks>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp" path="remarks" />
	/// </remarks>
	/// <example>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp" path="example" />
	/// </example>
	// Token: 0x02000066 RID: 102
	public class MelsecA3CNet1 : SerialDeviceBase
	{
		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.#ctor" />
		// Token: 0x0600084D RID: 2125 RVA: 0x0002D0A9 File Offset: 0x0002B2A9
		public MelsecA3CNet1()
		{
			base.ByteTransform = new RegularByteTransform();
			base.WordLength = 1;
		}

		/// <inheritdoc cref="P:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Station" />
		// Token: 0x1700017E RID: 382
		// (get) Token: 0x0600084E RID: 2126 RVA: 0x0002D0CE File Offset: 0x0002B2CE
		// (set) Token: 0x0600084F RID: 2127 RVA: 0x0002D0D6 File Offset: 0x0002B2D6
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		// Token: 0x06000850 RID: 2128 RVA: 0x0002D0E0 File Offset: 0x0002B2E0
		private OperateResult<byte[]> ReadWithPackCommand(byte[] command, byte station)
		{
			return base.ReadBase(MelsecA3CNet1OverTcp.PackCommand(command, station));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000851 RID: 2129 RVA: 0x0002D100 File Offset: 0x0002B300
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.ReadHelper(address, length, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000852 RID: 2130 RVA: 0x0002D13C File Offset: 0x0002B33C
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.WriteHelper(address, value, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000853 RID: 2131 RVA: 0x0002D178 File Offset: 0x0002B378
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.ReadBoolHelper(address, length, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000854 RID: 2132 RVA: 0x0002D1B4 File Offset: 0x0002B3B4
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] value)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.WriteHelper(address, value, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.RemoteRun" />
		// Token: 0x06000855 RID: 2133 RVA: 0x0002D1EE File Offset: 0x0002B3EE
		[HslMqttApi]
		public OperateResult RemoteRun()
		{
			return MelsecA3CNet1OverTcp.RemoteRunHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.RemoteStop" />
		// Token: 0x06000856 RID: 2134 RVA: 0x0002D207 File Offset: 0x0002B407
		[HslMqttApi]
		public OperateResult RemoteStop()
		{
			return MelsecA3CNet1OverTcp.RemoteStopHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.ReadPlcType" />
		// Token: 0x06000857 RID: 2135 RVA: 0x0002D220 File Offset: 0x0002B420
		[HslMqttApi]
		public OperateResult<string> ReadPlcType()
		{
			return MelsecA3CNet1OverTcp.ReadPlcTypeHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc />
		// Token: 0x06000858 RID: 2136 RVA: 0x0002D239 File Offset: 0x0002B439
		public override string ToString()
		{
			return string.Format("MelsecA3CNet1[{0}:{1}]", base.PortName, base.BaudRate);
		}

		// Token: 0x0400021D RID: 541
		private byte station = 0;
	}
}
